home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6883 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: tech.cftnet.com!not-for-mail
  2. From: wcowley@cftnet.com (Wes Cowley)
  3. Newsgroups: comp.windows.x.motif,comp.lang.c++
  4. Subject: Re: MOTIF Callbacks, C++ Member Functions - SOLVED
  5. Followup-To: comp.windows.x.motif,comp.lang.c++
  6. Date: 20 Feb 1996 11:02:59 GMT
  7. Organization: CFTnet
  8. Distribution: inet
  9. Message-ID: <4gc9p3$s7s@tech.cftnet.com>
  10. References: <4f6oau$c4m@knot.queensu.ca> <4f9fbo$7ju@news1.halcyon.com> <4gbf05$6d8@rex.sfe.com.au>
  11. NNTP-Posting-Host: ppp244_4.cftnet.com
  12. X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
  13.  
  14. Paul Hatchman (paul@sfe.com.au) wrote:
  15. : danubius@chinook.halcyon.com () writes:
  16. : >Wintermute  <3mal5@qlink.queensu.ca> wrote:
  17. : >>
  18. : >>The solution was to declare a static member function which is used as a 
  19. : >>callback.  Since it is static, there is no 'this' pointer, and it works 
  20. : >>fine.  To access the particular class instance, pass the 'this' pointer 
  21. : >>as client data when installing the callback, and it will be available 
  22. : >>when the static member function is called back.
  23. : >Which is exactly the method Doug Young uses in his book on Motif with
  24. : >C++.
  25. : >Joe
  26. : I dont think there are any guarantees that a compiler will give static
  27. : functions "C" style linkage. It works with every compiler I have tried, 
  28. : but I dont believe it is guaranteed to be portable.
  29. : Can someone give an authorative answer on this?
  30. :     - Paul
  31.  
  32. Static member functions don't get C linkage.  If they did it wouldn't be 
  33. possible to overload them.  Using static member functions for callbacks 
  34. where a C function is expected works because (in every environment I've 
  35. seen) the difference between C and C++ linkage is in type safety, not in 
  36. the parameter passing conventions.  Because the actual linkage between the
  37. callback and the server code is done at runtime, name mangling doesn't 
  38. matter and the argument types can't be checked.  Given that the parameters 
  39. are expected to be the same order and same size on both sides of the 
  40. call, it doesn't matter that the callback function actually has C++ linkage:
  41. it will work.
  42.  
  43. Somewhere, somebody's going to find a machine where that assumption doesn't
  44. hold true.  I imagine there's a fair amount of existing code that won't 
  45. run on it :)
  46.  
  47. Wes
  48.